package routes

import (
	"gin-app/app/controllers/app"
	"gin-app/app/controllers/common"
	"gin-app/app/middleware"
	"gin-app/app/services"
	"github.com/gin-gonic/gin"
	"net/http"
)

// SetApiGroupRoutes 定义 api 分组路由
func SetApiGroupRoutes(router *gin.RouterGroup) {
	// 测试接口
	router.GET("/ping", func(c *gin.Context) {
		c.String(http.StatusOK, "pong")
	})

	//模糊查询书籍
	//router.GET("/book/query_book", app.QueryBook)
	//router.GET("/book/query_novel", app.QueryNovel)
	//注册
	router.POST("/auth/register", app.Register)
	//登录
	router.POST("/auth/login", app.Login)

	//获取书籍列表（未分页）
	//router.GET("/book/get_book_list", app.GetBookList)
	//router.GET("/book/get_novel_list", app.GetNovelList)
	authRouter := router.Group("").Use(middleware.JWTAuth(services.AppGuardName))
	{
		//获取用户信息
		authRouter.GET("/auth/info", app.Info)
		//退出登录
		authRouter.POST("/auth/logout", app.Logout)
		//上传图片
		authRouter.POST("/image_upload", common.ImageUpload)

		//创建零售负责人
		authRouter.POST("/personincharge/create_retail", app.CreateRetailPersonInCharge)
		//删除零售负责人
		authRouter.POST("/personincharge/delete_retail", app.DeleteRetailPersonInCharge)
		//编辑零售负责人
		authRouter.POST("/personincharge/edit_retail", app.EditorRetailPersonInCharge)
		//获取零售负责人列表
		authRouter.GET("/personincharge/get_retails", app.GetRetailPersonInChargeList)
		//创建水源负责人
		authRouter.POST("/personincharge/create_waterSource", app.CreateWaterSourcePersonInCharge)
		//删除水源负责人
		authRouter.POST("/personincharge/delete_waterSource", app.DeleteWaterSourcePersonInCharge)
		//编辑水源负责人
		authRouter.POST("/personincharge/edit_waterSource", app.EditorWaterSourcePersonInCharge)
		//获取水源负责人列表
		authRouter.GET("/personincharge/get_waterSources", app.GetWaterSourcePersonInChargeList)

		//创建零售地
		authRouter.POST("/waterSource/create_retailArea", app.CreateRetailArea)
		//删除零售地
		authRouter.POST("/waterSource/delete_retailArea", app.DeleteRetailArea)
		//编辑零售地
		authRouter.POST("/waterSource/edit_retailArea", app.EditorRetailArea)
		//获取零售地列表
		authRouter.GET("/waterSource/get_retailAreas", app.GetRetailAreaList)
		//创建水源发源地
		authRouter.POST("/waterSource/create_waterSourceArea", app.CreateWaterSourceArea)
		//删除水源发源地
		authRouter.POST("/waterSource/delete_waterSourceArea", app.DeleteWaterSourceArea)
		//编辑水源发源地
		authRouter.POST("/waterSource/edit_waterSourceArea", app.EditorWaterSourceArea)
		//获取水源发源地列表
		authRouter.GET("/waterSource/get_waterSourceAreas", app.GetWaterSourceAreaList)
		////创建书籍
		//authRouter.POST("/book/create_book", app.CreateBook)
		//authRouter.POST("/book/create_novel", app.CreateNovel)
	}
	//测试优雅关闭接口
	//router.GET("/test", func(c *gin.Context) {
	//	time.Sleep(5 * time.Second)
	//	c.String(http.StatusOK, "success")
	//})
	//router.POST("/user/register", func(c *gin.Context) {
	//	var form request.Register
	//	if err := c.ShouldBindJSON(&form); err != nil {
	//		c.JSON(http.StatusOK, gin.H{
	//			"error": request.GetErrorMsg(form, err),
	//		})
	//		return
	//	}
	//	c.JSON(http.StatusOK, gin.H{
	//		"message": "success",
	//	})
	//})
}
